package mango.web.server.admin;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailViewS {
	/*
	public String send() {
		long start = System.currentTimeMillis();
		String mailArr[] = new String[] { "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com" };
		String result = "";
		System.out.println(mailArr.length);
		for (int i = 0; i < mailArr.length; i++) {
			long start2 = System.currentTimeMillis();
			try {
				HtmlEmail email = new HtmlEmail();
				
	//				email.setHostName("smtp.gmail.com");
	//				email.setFrom("mangomail002@gmail.com");
	//				//email.setSSL(true);
	//				email.setTLS(true);
	//				email.setAuthentication("mangomail002", "mango123456");
				

				email.setHostName("smtp.mail.yahoo.com");
				email.setFrom("mango_test1@yahoo.com");
				//email.setSSL(true);
				//email.setTLS(true);
				email.setAuthentication("mango_test1", "123456");

				
	//				email.setHostName("192.168.1.4");
	//				email.setFrom("mangomail001@hg");
	//				//email.setSSL(true);
	//				//email.setTLS(true);
	//				//email.setAuthentication("mangomail001", "mango123456");
				
				email.setSubject("New A simple mail SEND ONE");
				String mail = mailArr[i];
				email.addTo(mail);

				// embed the image and get the content id
				URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
				String cid = email.embed(url, "Apache logo");

				// set the html message
				email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");

				// set the alternative message
				email.setTextMsg("Your email client does not support HTML messages <br/> is this work <a href='google.com'>google</a>");

				// send the email
				email.send();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			long end2 = System.currentTimeMillis();
			String r = i + " " + mailArr[i] + " : " + (int) ((end2 - start2) / 1000) + " s.<br/>";
			System.out.println(r);
			result += r;
		}
		long end = System.currentTimeMillis();
		result += mailArr.length + " mails : " + (int) ((end - start) / 1000) + " s.<br/>";
		return result;
	}
	*/
	public String send2() {
		long start = System.currentTimeMillis();
		String mailArr[] = new String[] { "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com", "mangomail001@gmail.com", "mangomail001@yahoo.com", "mangomail002@gmail.com", "giangnhk20@gmail.com", "hgiang1984@yahoo.com", "giangnh84@yahoo.com", "giangnh0801@yahoo.com", "mango_test1@yahoo.com", "mango_test2@yahoo.com" };
		String result = "";
		System.out.println(mailArr.length);

		for (int i = 0; i < mailArr.length; i++) {
			long start2 = System.currentTimeMillis();
			try {
				String host = "smtp.mail.yahoo.com";
				String from = "mango_test1@yahoo.com";
				Properties properties = System.getProperties();
				properties.setProperty("mail.smtp.host", host);
				properties.setProperty("mail.smtp.auth", "true");
				//properties.setProperty("mail.smtp.starttls.enable", "true");
				Session session = Session.getDefaultInstance(properties, new javax.mail.Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
						return new PasswordAuthentication("mango_test1", "123456");
					}
				});

				String to = mailArr[i];
				MimeMessage message = new MimeMessage(session);
				message.setFrom(new InternetAddress(from));
				message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
				message.setSubject("This is the Subject Line!");
				message.setContent("<h1>This is actual message</h1> <a href='google.com'>google</a>", "text/html");
				Transport.send(message);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			long end2 = System.currentTimeMillis();
			String r = i + " " + mailArr[i] + " : " + (int) ((end2 - start2) / 1000) + " s.<br/>";
			System.out.println(r);
			result += r;
		}
		long end = System.currentTimeMillis();
		result += mailArr.length + " mails : " + (int) ((end - start) / 1000) + " s.<br/>";
		return result;
	}
}
